home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / dev / basic / ace24dist.lha / ace24.lha / SUBmods / Menu / Menu.b < prev    next >
Text File  |  1996-09-10  |  5KB  |  182 lines

  1. /*
  2. ** GadTools based menu subprogram library module. Permits
  3. ** menu subitems and normal ACE menu waiting and event trapping.
  4. **
  5. ** Adapted from RKM: Libraries (1992), p 368-378
  6. ** by David Benn, 22nd,23rd June 1996, 19th,20th July 1996, 8th,9th August 1996
  7. */
  8.  
  9. #include <exec/types.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/intuitionbase.h>
  12. #include <libraries/gadtools.h>
  13.  
  14. #include <funcs/exec_funcs.h>
  15. #include <funcs/gadtools_funcs.h>
  16. #include <funcs/intuition_funcs.h>
  17.  
  18. /*
  19. ** Structure definitions.
  20. */
  21. Struct menuInfo
  22.   Address visualInfo
  23.   Address menuStrip
  24. End Struct
  25.  
  26. /*
  27. ** Subprogram definitions.
  28. */
  29. Sub Address MakeMenu(Address theNewMenu,Shortint items) External
  30. /*
  31. ** Allocate space for required number of menu structures + 1.
  32. ** The extra item is for the NM_END marker. See EndMenu SUB.
  33. ** Store address in reference parameter and return it also.
  34. ** Note: the address may be NULL and the caller should test
  35. ** for this. 
  36. */
  37.       *&theNewMenu := Alloc((items+1)*Sizeof(NewMenu))
  38.     MakeMenu = *&theNewMenu
  39. End Sub
  40.  
  41. Sub AddMenuTitle(Address menuAddr, String theTitle) External
  42. /*
  43. ** Add a menu title to a GadTools menu.
  44. */
  45. Declare Struct NewMenu *theMenu
  46. Address strAddr
  47.     theMenu = *&menuAddr
  48.     theMenu->nm_Type = NM_TITLE
  49.     strAddr = Alloc(Len(theTitle)+1)
  50.     If strAddr = NULL Then Exit Sub
  51.     String titleClone Address strAddr
  52.     titleClone = theTitle
  53.     theMenu->nm_Label = @titleClone
  54.     theMenu->nm_CommKey = 0&
  55.     theMenu->nm_Flags = 0&
  56.     theMenu->nm_MutualExclude = 0&
  57.     theMenu->nm_UserData = 0&
  58.     *&menuAddr := theMenu+Sizeof(NewMenu)    
  59. End Sub
  60.  
  61. Sub AddMenuItem(Address menuAddr, String theItem, String commKey) External
  62. /*
  63. ** Add a menu item to a GadTools menu.
  64. */
  65. Declare Struct NewMenu *theMenu
  66. Address strAddr
  67.     theMenu = *&menuAddr
  68.     theMenu->nm_Type = NM_ITEM
  69.     strAddr = Alloc(Len(theItem)+1)
  70.     If strAddr = NULL Then Exit Sub
  71.     String itemClone Address strAddr
  72.     itemClone = theItem
  73.     theMenu->nm_Label = @itemClone
  74.     If commKey = "" Then 
  75.         theMenu->nm_CommKey = 0&
  76.     Else
  77.         strAddr = Alloc(Len(commKey)+1)
  78.         If strAddr = NULL Then Exit Sub
  79.         String commKeyClone Address strAddr
  80.         commKeyClone = commKey
  81.         theMenu->nm_CommKey = @commKeyClone
  82.     End If
  83.     theMenu->nm_Flags = 0&
  84.     theMenu->nm_MutualExclude = 0&
  85.     theMenu->nm_UserData = 0&
  86.     *&menuAddr := theMenu+Sizeof(NewMenu)    
  87. End Sub
  88.  
  89. Sub AddMenuSubItem(Address menuAddr, String theSubItem) External
  90. /*
  91. ** Add a menu subitem to a GadTools menu.
  92. */
  93. Declare Struct NewMenu *theMenu
  94. Address strAddr
  95.     theMenu = *&menuAddr
  96.     theMenu->nm_Type = NM_SUB
  97.     strAddr = Alloc(Len(theSubItem)+1)
  98.     If strAddr = NULL Then Exit Sub
  99.     String subItemClone Address strAddr
  100.     subItemClone = theSubItem
  101.     theMenu->nm_Label = @subItemClone
  102.     theMenu->nm_CommKey = 0&
  103.     theMenu->nm_Flags = 0&
  104.     theMenu->nm_MutualExclude = 0&
  105.     theMenu->nm_UserData = 0&
  106.     *&menuAddr := theMenu+Sizeof(NewMenu)
  107. End Sub
  108.  
  109. Sub AddMenuBarItem(Address menuAddr) External
  110. /*
  111. ** Add a menu bar to a GadTools menu.
  112. */
  113. Declare Struct NewMenu *theMenu
  114.     theMenu = *&menuAddr
  115.     theMenu->nm_Type = NM_ITEM
  116.     theMenu->nm_Label = NM_BARLABEL
  117.     theMenu->nm_CommKey = 0&
  118.     theMenu->nm_Flags = 0&
  119.     theMenu->nm_MutualExclude = 0&
  120.     theMenu->nm_UserData = 0&
  121.     *&menuAddr := theMenu+Sizeof(NewMenu)
  122. End Sub
  123.  
  124. Sub EndMenu(Address menuAddr) External
  125. /*
  126. ** Mark the end of a GadTools menu.
  127. */
  128. Declare Struct NewMenu *theMenu
  129.     theMenu = menuAddr
  130.     theMenu->nm_Type = NM_END
  131.     theMenu->nm_Label = 0&
  132.     theMenu->nm_CommKey = 0&
  133.     theMenu->nm_Flags = 0&
  134.     theMenu->nm_MutualExclude = 0&
  135.     theMenu->nm_UserData = 0&
  136. End Sub
  137.  
  138. Sub Longint DisplayMenu(Address winAddr, Address menuAddr, Address infoAddr) External
  139. /*
  140. ** Gets current screen's visual info for GadTools, Creates 
  141. ** Intuition menus from GadTools menu description info, 
  142. ** lays out the menus and displays them.
  143. */
  144. Declare Struct _Window *win
  145. Declare Struct menuInfo *menuInfo
  146.  
  147.   Library "gadtools"
  148.  
  149.   win = winAddr
  150.   menuInfo = infoAddr
  151.  
  152.   menuInfo->visualInfo = GetVisualInfoA(win->WScreen,NULL)
  153.   If menuInfo->visualInfo Then
  154.       menuInfo->menuStrip = CreateMenusA(menuAddr,NULL)
  155.       If menuInfo->menuStrip Then
  156.         If LayoutMenusA(menuInfo->menuStrip,menuInfo->visualInfo,NULL) Then
  157.           SetMenuStrip(win,menuInfo->menuStrip)
  158.           DisplayMenu = TRUE
  159.     Else
  160.       DisplayMenu = FALSE
  161.     End If
  162.       Else
  163.     DisplayMenu = FALSE
  164.       End If
  165.   Else
  166.    DisplayMenu = FALSE
  167.   End If
  168. End Sub
  169.  
  170. Sub DestroyMenu(Address win, Address infoAddr) External
  171. /*
  172. ** Clears the specified window's menu strip, frees the resources
  173. ** associated with the menus and with the GadTools visual info.
  174. */
  175. Declare Struct menuInfo *menuInfo
  176.   menuInfo = infoAddr
  177.   ClearMenuStrip(win)
  178.   FreeMenus(menuInfo->menuStrip)
  179.   FreeVisualInfo(menuInfo->visualInfo)
  180.   Library Close "gadtools"
  181. End Sub
  182.